package tree;

import org.junit.BeforeClass;

public class Test {
    private static LinkedNode s_pLinkNode;

    @BeforeClass
    public static void createLinkedTree() {
        createSimpleTree();
        createBinTree();
    }

    //随便构建一个树
    public static void createSimpleTree() {
        s_pLinkNode = new LinkedNode();
        s_pLinkNode.setObjData(-1);
        LinkedNode pCurrentNode = s_pLinkNode;
        for (int i = 0; i < 20; i++) {
            LinkedNode leftNode = new LinkedNode();
            leftNode.setObjData(i);
            LinkedNode rightNode = new LinkedNode();
            rightNode.setObjData(i);
            pCurrentNode.setLeftNode(leftNode);
            pCurrentNode.setRightNode(rightNode);
            pCurrentNode = leftNode;
        }
    }

    public static void createBinTree() {
        int[] arrSrc = new int[] {1,2,3,4,5,6,8,9,10,11,12};
        LinkedNode pNode = new LinkedNode();
        pNode.setObjData(7);
        for (int i = 0; i < arrSrc.length; i++) {
            BinTree.insert(arrSrc[i], pNode);
        }
        s_pLinkNode = pNode;
    }

    @org.junit.Test
    public void testPreOrderPrint() {
        new OrderPrint().preOrderPrint(s_pLinkNode);
        System.out.println("\r\n");
    }

    @org.junit.Test
    public void testInOrderPrint() {
        new OrderPrint().inorderPrint(s_pLinkNode);
        System.out.println("\r\n");
    }

    @org.junit.Test
    public void testAfterOrderPrint() {
        new OrderPrint().afterOrderPrint(s_pLinkNode);
        System.out.println("\r\n");
    }

    @org.junit.Test
    public void testSimpleFind() {
        new OrderPrint().preOrderPrint(s_pLinkNode);
        LinkedNode pNode = BinTree.find(0, s_pLinkNode);
        System.out.println(pNode);
        new OrderPrint().preOrderPrint(s_pLinkNode);
    }

}
